package com.Excrises;

import java.util.Objects;

public class Goods implements Comparable<Goods>{
    private int num;
    private String name;                 //商品型号
    private double price;                //商品单价

    public int getId() {
        return num;
    }

    public String getName() {
        return name;
    }


    public Goods(int num, String name) {
        this.num = num;
        this.name = name;
    }

    public double getPrice() {
        int NAME = getId();

        switch (NAME){
            case 001: price = 2000; break;
            case 002: price = 30000; break;
            default: price = 150000;
        }

        return price;
    }

    public void setId(int id) {
        this.num = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Goods{" +
                "num=" + num +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    @Override
    public int hashCode() {
        return Objects.hash(num, name, price);
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public int compareTo(Goods o) {
        return Double.compare(this.price,o.getPrice());
    }


}
